package com.kawa.kemanage.controller.api;

import com.kawa.kemanage.entity.UserFeedback;
import com.kawa.kemanage.service.UserFeedbackService;
import com.kawa.kemanage.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping({"/api/feekback"})
public class UserFeedbackController {
    @Autowired
    private UserFeedbackService userFeedbackService;

    /**
     * 查询用户反馈列表
     * @param pageNo
     * @return
     */
    @RequestMapping("/queryFeekback")
    public Result queryFeekback(@RequestParam(required = false,defaultValue = "1")Integer pageNo,
                                @RequestParam(required = false)String type,
                                @RequestParam(required = false) String status){
        return  Result.success(userFeedbackService.queryFeekBack(pageNo,10,type,status));
    }

    //根据id查看
    @RequestMapping("/queryFeekbackById")
    public Result queryFeekbackById(@RequestParam(required = false) Integer feedback_id){
        return  Result.success(userFeedbackService.selectFeekbackById(feedback_id));
    }

    /**
     * 删除反馈信息
     * @param feedback_id
     * @return
     */
    @RequestMapping("/delFeekback/{feedback_id}")
    public Result delFeekback(@PathVariable Integer feedback_id){
        if (userFeedbackService.delFeekback(feedback_id)) {
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }

    @PostMapping("/addFeekback")
    public Result addFeekback(@RequestBody UserFeedback userFeedback){
        if (userFeedbackService.addFeekback(userFeedback)){
            return  Result.success("添加成功");
        }else {
            return  Result.error("添加失败");
        }
    }

    @PostMapping("/updateFeekback")
    public  Result updateFeekback(@RequestBody UserFeedback userFeedback){
        if (userFeedbackService.update(userFeedback)){
            return  Result.success("修改成功");
        }else {
            return  Result.error("修改失败");
        }
    }

    /**
     * 反馈类型统计接口
     * @return
     */
    @GetMapping("/status")
    public Result getFeedbackStats() {
        Map<String, Integer> stats = userFeedbackService.getFeedbackStats();
        return Result.success(stats);
    }

    @GetMapping("/getByUserId")
    public  Result getByUserId(@RequestParam(required = false) Integer user_id){
        return Result.success(userFeedbackService.queryFeedbacksByUserId(user_id));
    }

}
